/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2023/2/27 19:49
 * @Version 1.0
 */
package com.eight.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eight.dao.CarTypeDao;
import com.eight.pojo.TbCarType;
import com.eight.service.CarTypeService;
import com.eight.vo.CarVo;
import com.eight.vo.ComResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarTypeServiceImpl implements CarTypeService {

    @Autowired
    private CarTypeDao carTypeDao;

    @Override
    public ComResult selectAllType(CarVo carVo) {
        Page<Object> pa = PageHelper.startPage(carVo.getPageNum(), carVo.getPageSize());
        QueryWrapper<TbCarType> wrapper=null;
        if (carVo.getName()!=null){
           wrapper=new QueryWrapper<>();
           wrapper.like(" type_name",carVo.getName());
        }
        List<TbCarType> tbCarTypes = carTypeDao.selectList(wrapper);
        PageInfo<TbCarType> info=new PageInfo<>(tbCarTypes);
        return new ComResult(2000,"查询成功",info);
    }

    @Override
    public ComResult selectAllType() {
        List<TbCarType> tbCarTypes = carTypeDao.selectList(null);
        return new ComResult(2000,"查询成功",tbCarTypes);
    }

    @Override
    public ComResult insert(TbCarType type) {
        int insert = carTypeDao.insert(type);
        return new ComResult(2000,"添加类型成功",insert);
    }

    @Override
    public ComResult delete(Integer id) {
        int delete = carTypeDao.deleteById(id);
        return new ComResult(2000,"删除类型成功",delete);
    }

    @Override
    public ComResult update(TbCarType type) {
        int update = carTypeDao.updateById(type);
        return new ComResult(2000,"修改类型成功",update);
    }

    /**
     * 查询移动端车辆的类型
     * @return
     */
    @Override
    public ComResult getCarType() {
        List<TbCarType> tbCarTypes = carTypeDao.selectList(null);
        System.out.println(tbCarTypes);
        return new ComResult(2000,"查询成功",carTypeDao.selectList(null));
    }


}

